import PyPDF2
import re

def search_upload_content():
    try:
        pdf_file = open('FastAPI.pdf', 'rb')
        pdf_reader = PyPDF2.PdfReader(pdf_file)
        text = ''
        for page in pdf_reader.pages:
            text += page.extract_text()
        pdf_file.close()
        
        # 搜索文件上传相关内容
        upload_keywords = ['upload', 'Upload', '文件上传', 'File', 'form', 'Form']
        upload_content = []
        lines = text.split('\n')
        
        for i, line in enumerate(lines):
            for keyword in upload_keywords:
                if keyword in line:
                    # 获取当前行及其前后几行
                    start = max(0, i-3)
                    end = min(len(lines), i+4)
                    context = '\n'.join(lines[start:end])
                    upload_content.append(context)
                    break
        
        return '\n\n---\n\n'.join(upload_content)
    except Exception as e:
        return f"Error reading PDF: {str(e)}"

if __name__ == '__main__':
    content = search_upload_content()
    print(content)